package com.yami.shop.personnft.common.listener;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.bean.event.UserDestroyPersonnftEvent;
import com.yami.shop.bean.model.ChannelUserRelationRecord;
import com.yami.shop.bean.model.UserNftAddressBook;
import com.yami.shop.service.ChannelUserRelationRecordService;
import com.yami.shop.service.UserNftAddressBookService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 确认订单信息时的默认操作
 *
 * @author LGH
 */
@Slf4j
@Component("userDestroyPersonnftListener")
@AllArgsConstructor
public class UserDestroyPersonnftListener {

    @Autowired
    private ChannelUserRelationRecordService channelUserRelationRecordService;
    @Autowired
    private UserNftAddressBookService userNftAddressBookService;
    /**
     * 注销钱包关系
     */
    @EventListener(UserDestroyPersonnftEvent.class)
    @Async("lazyTraceExecutor")
    public void defaultBusinessAddPersonnListener(UserDestroyPersonnftEvent event) {
        channelUserRelationRecordService.remove(new LambdaQueryWrapper<ChannelUserRelationRecord>().eq(ChannelUserRelationRecord::getUserId, event.getUserId()));
        LambdaQueryWrapper<UserNftAddressBook> aueryWrapper1 = new LambdaQueryWrapper<>();
        aueryWrapper1.and(wrapper -> wrapper.eq(UserNftAddressBook::getUserId, event.getUserId()).or().eq(UserNftAddressBook::getChannelUserId, event.getUserId()));
        userNftAddressBookService.remove(aueryWrapper1);
    }
}
